package xdpm.nhom16.DAO;

import xdpm.nhom16.DTO.QuanHuyenDTO;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class QuanHuyenDAO extends AbstractDAO<QuanHuyenDTO> {
	

	public static final String TABLE_NAME = "QuanHuyen";
	private static final String COLUMN_ID = "MaQuanHuyen";
	public static final String[] NAME_COLUMNS = new String[] { COLUMN_ID, "TenQuanhuyen" };

	public QuanHuyenDAO(SQLiteDatabase db) {
		super(db);
		// TODO Auto-generated constructor stub
	}

	public int GetIdByName(String name) {
		int result = -1;
		try {
			Cursor cursor = database.query(getTableName(), getNameColumns(),
					"TenDuong='" + name + "'", null, null, null, null);
			cursor.moveToFirst();
			result = cursor.getInt(0);
		} catch (Exception e) {
			result = -1;
		}
		return result;
	}

	@Override
	protected String getTableName() {
		// TODO Auto-generated method stub
		return TABLE_NAME;
	}

	@Override
	protected String getNameColumnId() {
		// TODO Auto-generated method stub
		return COLUMN_ID;
	}

	@Override
	protected String[] getNameColumns() {
		// TODO Auto-generated method stub
		return NAME_COLUMNS;
	}

	@Override
	protected QuanHuyenDTO cusorToDTO(Cursor cursor) {
		// TODO Auto-generated method stub
		QuanHuyenDTO result = new QuanHuyenDTO();
		result.setMaQuanHuyen(cursor.getInt(0));
		if (!cursor.isNull(1))
			result.setTenQuanHuyen(cursor.getString(1));
		return result;
	}
}
